package cn.kgc.controller;


import cn.kgc.dto.EvaluateDto;
import cn.kgc.dto.MalfunctionDto;
import cn.kgc.dto.Result;
import cn.kgc.pojo.Evaluate;
import cn.kgc.service.EvaluateService;
import cn.kgc.service.MalfunctionService;
import cn.kgc.utils.redis.ResultUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 评估信息 前端控制器
 * </p>
 *
 * @author qf
 * @since 2022-03-03
 */
@RestController
@RequestMapping("/api/evaluate")
public class EvaluateController {
    private final MalfunctionService malfunctionService;

    private final EvaluateService evaluateService;


    public EvaluateController(MalfunctionService malfunctionService,  EvaluateService evaluateService) {
        this.malfunctionService = malfunctionService;
        this.evaluateService = evaluateService;
    }

    @GetMapping("/specList")
    public Result specList(Long modelId){
        List<MalfunctionDto> list = malfunctionService.specList(modelId);
        Result result = ResultUtils.returnDataSuccess(list);
        return result;
    }
    @PostMapping("/assess")
    public Result<Evaluate> assess(Long modelId, String optionIds, HttpServletRequest request){
        String token = request.getHeader("token");
        if(token==null||"".equals(token)){
            ResultUtils.returnFail();
        }
       Evaluate evaluate=evaluateService.assess(modelId,optionIds,token);

       return ResultUtils.returnDataSuccess(evaluate);
    }
    @GetMapping("/{id}/assessInfo")
    public Result assessInfo(@PathVariable Long id){
        EvaluateDto evaluateDto=evaluateService.assessInfo(id);
        Result result = ResultUtils.returnDataSuccess(evaluateDto);
        return result;
    }
}

